//
//  JingShowViewController.m
//  FlowerRainGround
//
//  Created by lanou on 16/4/26.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "JingShowViewController.h"
#import "BuyGoodsViewController.h"
@interface JingShowViewController ()
@property (strong, nonatomic) IBOutlet UIWebView *JingWebView;

@end



@implementation JingShowViewController




- (void) requestData{
    
    if (self.typeID == 0) {
        //typeID为0是精选
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://m.htxq.net/shop/PGoodsAction/goodsDetail.do?goodsId=%@", self.jingModel.fnId]]];
        [self.JingWebView loadRequest:request];
    }else{
        //商城
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://m.htxq.net/shop/PGoodsAction/goodsDetail.do?goodsId=%@", self.mallmodel.fnId]]];
        [self.JingWebView loadRequest:request];
    }
    
}


- (void) creatView{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight - 120, kWidth, 130)];
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 40, 40)];
    imageview.image = [UIImage imageNamed:@"gouwu"];
    [view addSubview:imageview];
    
    UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 80, 40)];
    if (self.typeID == 0) {
        pricelabel.text = [NSString stringWithFormat:@"￥%ld",self.jingModel.goodsmodel.fnPrice];
    }else{
        pricelabel.text = [NSString stringWithFormat:@"￥%ld", self.mallmodel.fnMarketPrice];
    }
    [view addSubview:pricelabel];
    
    UIButton *joinButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [joinButton setTitle:@"加入购物车" forState:UIControlStateNormal];
    joinButton.frame = CGRectMake(180, 0, 100, 60);
    joinButton.backgroundColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.6 alpha:1.0];
    [joinButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    joinButton.titleLabel.font = [UIFont systemFontOfSize:20];
    [view addSubview:joinButton];
    
    UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [buyButton setTitle:@"购买" forState:UIControlStateNormal];
    [buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    buyButton.block = ^(){
        [self buy];
    };
    
    buyButton.frame = CGRectMake(280, 0, kWidth - 270, 60);
    buyButton.titleLabel.font = [UIFont systemFontOfSize:20];
    buyButton.backgroundColor = [UIColor blackColor];
    [view addSubview:buyButton];
    
    view.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:view];
}

//点击购买
- (void) buy{
    BuyGoodsViewController *goods = [[BuyGoodsViewController alloc] init];
    if (self.typeID == 0) {
        goods.typeID = 0;
        goods.jingModel = self.jingModel;
    }
    else{
        goods.typeID = 1;
        goods.mallmodel = self.mallmodel;
    }
    
    
    [self.navigationController pushViewController:goods animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestData];
    self.navigationItem.title  = self.jingModel.fnName;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self creatView];
    });
    
    
    
    
    
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
